<template>
  <div style="padding:10px;height:100%; ">
    <el-form :inline="true">

      <el-form-item>
        <el-button
          type="primary"
          @click="report"
          icon="delete"
        >数据上报</el-button>

      </el-form-item>
  
    </el-form>
    <el-table
      style="width:100%"
      :data="list"
      height="500px"
      v-loading="listLoading"
      element-loading-text="Loading"
      ref="table"
    
      border
    >
      
      <el-table-column
        align="center"
        type="index"
        width="50"
        label="序号"
        fixed="left"
      >
        <template slot-scope="scope">
          <span>{{(currentPage- 1) * pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>

      <DataListItem
        v-bind:key="$index"
        v-for="(item,$index) in cols"
        :column="item"
      />

    </el-table>
    
<el-dialog
  title="输入登录密码"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
   <el-form >
     <el-form-item label="密码">
          <el-input  type="password" v-model="password"/>
      </el-form-item>
    </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="ok">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>
<script>
import Vue from "vue";
import { getCheckList } from "@/api/权限";
import request from "@/utils/request";
import { getUser } from "@/utils/auth";
import linq from "linq";
import axios from "axios";
import { report,getReportList } from "@/api/权限";
export default {
  components: {
    DataListItem: {
      name: "DataListItem",
      template: `<el-table-column :label='column.label' :prop='column.prop' align="center">
          
          <DataListItem :key="$index" v-for="(item,$index) in column.data?column.data:[]" :column="item" />
          </el-table-column>
          `,
      props: ["column"]
    }
  },
  data: function() {
    return {
      model: {},
      dialogVisible:false,
      search_str: "",
      cols: [{ label: "上报工号", prop: "Code" }, { label: "上报时间", prop: "ReceiveTime" }],
      listLoading: true,
      list: [],
      password:'',
      currentPage: 1,
      pageSize: 20,
      user: null
    };
  },

  async created() {
    //

    this.listLoading = true;
    
    var result = await getReportList(this.$root.user.XXID,this.$root.user.CJPC,this.$root.user.PASSWORD);
    this.list = result;
    this.listLoading = false;

    //
  },

  methods: {
    report(){
        this.dialogVisible = true;
    },
    async ok(){
      try{
      if(getUser().PASSWORD == this.password){
        
          this.dialogVisible = false;
        this.listLoading = true;
        var user = getUser();
        var datas = await getCheckList(user.XXID, user.CJPC);
      
        if(datas.length>0){
          throw "数据检测存在问题,请打开数据检测查看其中问题并纠正";
        }
        await report(this.$root.user.XXID,this.$root.user.CJPC,this.$root.user.PASSWORD);
        
        var result = await getReportList(this.$root.user.XXID,this.$root.user.CJPC);
        this.list = result;
    
      
        this.$alert("更新成功");

      }else{
        this.$alert("密码不对");
      }
      
       }catch(e){
        this.$alert(e);
      }finally{
         this.listLoading = false;
      }
    },
    handleSizeChange: function(size) {
      this.pageSize = size;
    },
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage;
    }
  }
};
</script>